<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>

<body>
  <div id="app">
    <button v-for='title in  titles' :key="title" @click="currentCom = title">
      {{title}}
    </button>
    <!-- <keep-alive>
      <component :is="currentCom"></component>
    </keep-alive> -->
    <!-- <keep-alive include="ComA,ComB"> -->
      <!-- <keep-alive include="/Com[A,B]"> -->
    <!-- <keep-alive :include="['ComA', 'ComB']"> -->
    <!-- <keep-alive :include="/Com[AB]/">
      <component :is="currentCom"></component>
    </keep-alive> -->

    <!-- <keep-alive exclude="ComC">
      <component :is="currentCom"></component>
    </keep-alive>

    <keep-alive exclude="ComC,ComB">
      <component :is="currentCom"></component>
    </keep-alive> -->
    <!-- <keep-alive :exclude="['ComC']">
      <component :is="currentCom"></component>
    </keep-alive> -->

    <keep-alive max="2">
      <component :is="currentCom"></component>
    </keep-alive>
  </div>
</body>
<script src="../lib/vue.js"></script>
<script>
  var ComA = {
    template: `<p>这是组件A<input type="text"></p>`
  }
  var ComB = {
    template: `<p>这是组件B<input type="text"></p>`
  }
  var ComC = {
    template: `<p>这是组件C<input type="text"></p>`
  }
  new Vue({
    el: '#app',
    data: {
      titles: ['ComA', 'ComB', 'ComC'],
      currentCom: 'ComA'
    },
    components: {
      ComA, ComB, ComC
    }
  })
</script>

</html>